// 导入数据库连接文件
const { connect } = require("../model/mongodb");
// 立即执行函数
(async () => {
  await connect(); // 执行连接数据库任务
})();
const userRouter = require("../routers/user.routes");
const msgRouter = require("../routers/message.routes");
// const friendRouter = require('../routers/friend.routes')
const handler = require("../middleWares/handler");
const { verifyToken } = require("../utils/token");
const Koa = require("koa");
const cors = require("koa2-cors");
const bodyparser = require("koa-bodyparser");
const http = require("http");
const webSocketService = require("../controllers/socket.controller");

//当前在线用户
global.userList = [];
const app = new Koa({
  proxy: true
});
app.use(bodyparser());
app.use(handler);
app.use(cors());
app.use(verifyToken);
app.use(userRouter.routes());
app.use(msgRouter.routes());
// app.use(friendRouter.routes())
// webSocketService.listen();
const server = http.createServer(app.callback());
webSocketService(server);
server.listen(3009);
module.exports = app;
